<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="../../js/popup.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="../../css/popup.css" type="text/css"  charset="utf-8"/>
<script type="text/javascript">
// <![CDATA[
	function upload() {
		document.file_upload.submit();
  	}
	function done() {
		if (typeof(execAttach) == 'undefined') { //Virtual Function
	        return;
	    }
		var fileSize = '${requestScope.f_size}';
		var _mockdata = {
			'attachurl':'${pageContext.request.contextPath}${requestScope.f_path}',
			'filemime': '${requestScope.f_type}',
			'uploadpath': '${requestScope.upload_path}',
			'filename': '${requestScope.f_original}',
			'thumburl': '${requestScope.f_tmb}',
			'filesize': Number(fileSize)
		};
		execAttach(_mockdata);
		closeWindow();
	}

	function initUploader(){
	    var _opener = PopupUtil.getOpener();
	    if (!_opener) {
	        alert('잘못된 경로로 접근하셨습니다.');
	        return;
	    }
	    
	    var _attacher = getAttacher('file', _opener);
	    registerAction(_attacher);
	}
	
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body onload="initUploader();">
<div class="wrapper">
	<div class="header">
		<h1>파일 첨부</h1>
	</div>
	
<c:choose>
	<c:when test="${requestScope.error != null }">
		<div class="body">
	  		<form name="file_upload" id="file_upload" action="uploadFile.jsp" method="post" enctype="multipart/form-data" accept-charset="utf-8">
				<dl class="alert">
				    <dt>파일 첨부 하기</dt>
				    <dd>
				    첨부 파일 크기는 20MB 까지 가능합니다.<br /><br />
				    파일 용량이 커 업로드에 실패하였습니다.<br />
				    다시 시도해 주세요.<br /><br />
				    </dd>
				    <dd>
		        	<input type="file" name="uploadFile" size="30">
					</dd>
				</dl>
			</form>
		</div>
		<div class="footer">
			<p><a href="#" onclick="closeWindow();" title="닫기" class="close">닫기</a></p>
			<ul>
				<li class="submit"><a href="#" onclick="upload();" title="업로드" class="btnlink">업로드</a> </li>
				<li class="cancel"><a href="#" onclick="closeWindow();" title="취소" class="btnlink">취소</a></li>
			</ul>
		</div>
	</c:when>
	<c:when test="${requestScope.f_original == null}">
		<div class="body">
	  		<form name="file_upload" id="file_upload" action="uploadFile.jsp" method="post" enctype="multipart/form-data" accept-charset="utf-8">
				<dl class="alert">
				    <dt>파일 첨부 하기</dt>
				    <dd>
				    첨부 파일 크기는 20MB 까지 가능합니다.<br /><br />
				    </dd>
				    <dd>
		        	<input type="file" name="uploadFile" size="30">
					</dd>
				</dl>
			</form>
		</div>
		<div class="footer">
			<p><a href="#" onclick="closeWindow();" title="닫기" class="close">닫기</a></p>
			<ul>
				<li class="submit"><a href="#" onclick="upload();" title="업로드" class="btnlink">업로드</a> </li>
				<li class="cancel"><a href="#" onclick="closeWindow();" title="취소" class="btnlink">취소</a></li>
			</ul>
		</div>
	</c:when>
	<c:otherwise>
		<div class="body">
			<dl class="alert">
			    <dt>파일 첨부 확인</dt>
			    <dd>
			    	등록을 누르시면 <b>"${requestScope.f_original}"</b> 파일이 첨부됩니다.<br /> 
				</dd>
			</dl>
		</div>
		<div class="footer">
			<p><a href="#" onclick="closeWindow();" title="닫기" class="close">닫기</a></p>
			<ul>
				<li class="submit"><a href="#" onclick="done();" title="확인" class="btnlink">확인</a> </li>
				<li class="cancel"><a href="#" onclick="closeWindow();" title="취소" class="btnlink">취소</a></li>
			</ul>
		</div>
	</c:otherwise>
</c:choose>	
</div>
</body>
</html>